//用于进行手机和用户两种登陆的切换
$("#login .row .title div").on("click",function(){
	$(this).children("span").addClass("active").parent().siblings().children("span").removeClass("active");
	var index = $(this).index();
	$("#login .content").children().eq(index).show().siblings().hide();
	
})




//用户名失去焦点的操作
$("#login .userBox .first input").on("blur",function(){
	username("#login .userBox .first input","#login .userBox .first .msgdiv span")
})

//验证密码  
$("#login .userBox .second input").on("blur",function(){
	passwo("#login .userBox .second input","#login .userBox .second .msgdiv span")
})

//眼睛按钮用于看密码的状态
var loginNum = 0; 
$("#login .userBox .input .iconfont,#login .telephoneBox .input .iconfont").click(function(){
	loginNum += 1;
	if(loginNum % 2 == 1){
		$(this).siblings("input").attr("type","text")
	}else{
		$(this).siblings("input").attr("type","password")
	}
	
})


//用户页的提交按钮
//$("#login .userBox .second input,#login .userBox .first input").on("keydown",function(){
//	if(ok1 && ok2){
//		
//		$("#login .userBox .five div").css({
//			background:"#0069ff",
//			color:"#fff"
//		})
//	}
//	
//})

$("#login .userBox .five div").click(function(){
	if(!$("#login .userBox .four input[type='checkbox']").is(":checked")){
		$("#shade").show();
		$("#warning").show();
		$("#warning p.secondP").html("未了您的个人权益，请您同意协议")
	}else{
		passwo("#login .userBox .second input","#login .userBox .second .msgdiv span");
		username("#login .userBox .first input","#login .userBox .first .msgdiv span");
		var user = $(".loginUser").val();
		var pass = $(".loginPasswkord").val();
		console.log(user,pass)
		if( ok1 && ok2){
			$.ajax({
				url:ptms.url.common.limitControl.login,
				type:"POST",
				data:{
					"username": user,
					"password":pass
				},
				success:function(date){
					if(date.data == 1){
						alert("注册成功！请登录");
						window.location.href = "register.html";
					}else if(date.data == 0){
						alert(data.Message)
					}
					
				}
				
			})
//			$.post("http://192.168.4.36:2223/manage/upms/user/create","username=asdfasdfsafasd&password=sadfasdfsadf",function(data){
//				console.log(data)
//			})
		}
	}
})

//验证手机号输入
$("#login .telephoneBox .first input").blur(function(){
	phoneName1("#login .telephoneBox .first input","#login .telephoneBox .first .msgdiv span")
})

//验证密码
$("#login .telephoneBox .second input").blur(function(){
	passwo("#login .telephoneBox .second input","#login .telephoneBox .second .msgdiv span")

})

	
//获取验证码的计时功能

var loginObject = {
	num : 60,
	testState:false,
	protocolState:false
}

var loginTemp;
$("#login .telephoneBox .third input[type='button']").click(function(){
	
	clearInterval(loginTemp)
	phoneName1("#login .telephoneBox .first input","#login .telephoneBox .first .msgdiv span");
	if(ok3){
		
		$(this).attr("disabled","true");
		loginTemp = setInterval(function(){
			--loginObject.num;
			$("#login .telephoneBox .third input[type='button']").val(loginObject.num + "s");
			if(loginObject.num < 1){
				$("#login .telephoneBox .third input[type='button']").disabled = false;
				clearInterval(loginTemp);
				$(this).removeAttr("disabled");
				loginObject.num = 60;
				$("#login .telephoneBox .third input[type='button']").val("获取验证码")
			}
		},1000)
	}
})


//验证码的判断函数
function judgeTestState(){
	var val = $("#login .telephoneBox .third .firstInput").val();
	$.ajax({
		url:"",
		type:"",
		data:{
			val:val
		},
		success:function(data){
			loginObject.testState = true;
		},
		error:function(data){
			loginObject.testState = false;
		}
	})
}

$("#login .telephoneBox .five div").on("click",function(){
	if(!$("#login .telephoneBox .four input[type='checkbox']").is(":checked")){
		$("#shade").show();
		$("#warning").show();
		$("#warning p.secondP").html("未了您的个人权益，请您同意协议")
	}else{
		//	用于判断验证码的状态
		judgeTestState()
		if(!loginObject.testState){
			$("#login .telephoneBox .third .msgdiv span").html("验证码有误");
		}else{
			$("#login .telephoneBox .third .msgdiv span").html("");
			
			phoneName1("#login .telephoneBox .first input","#login .telephoneBox .first .msgdiv span");
			passwo("#login .telephoneBox .second input","#login .telephoneBox .second .msgdiv span");
			if(ok3 && ok2){
				
			}
		}
	}

})

//用于关闭遮罩层和提示框
$("#warning p.firstP span").on("click",function(){
	$("#shade").hide();
	$("#warning").hide();
})




